#include<iostream>

using namespace std;

int main()
{
	int n;
	cin>>n;
	while(n)
	{
		while(n/10)
		{
			int i=n;
			int sum=0;
			while(i)
			{
				sum+=i%10;
				i/=10;
			}
			n=sum;
		}
		cout<<n<<endl;
		cin>>n;
	}
}
